/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-04-22
 * Time: 14:19
 */

import java.io.*;
import java.util.Scanner;

/**
 * 将一个文件的内容复制到另一个文件中
 *
 */
public class Demo4 {
    public static void main(String[] args) {
        Scanner  scanner = new Scanner(System.in);
        System.out.println("请输入一个文件源");
        String begin = scanner.next();
        System.out.println("请输入目标文件");
        String end = scanner.next();
       File f1= new File(begin);
       if(!f1.isFile()){
           System.out.println("文件源错误");
           return;
       }
       File f2 = new File(end) ;
        System.out.println(f2.getParentFile().getAbsolutePath());
       if(!f2.getParentFile().isDirectory()) {
           System.out.println("=========");
           return;
       }

       try(InputStream inputStream = new FileInputStream(f1);
           OutputStream outputStream = new FileOutputStream(f2)){
           while(true){
               byte[] bytes = new byte[1024];
               int n = inputStream.read(bytes);
               if(n==-1){
                   break;
               }
               outputStream.write(bytes,0,n);
           }

       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }

    }
}
